package org.htmlparser.visitors;

import org.htmlparser.Node;
import org.htmlparser.Tag;
import org.htmlparser.util.NodeList;

public class TagFindingVisitor extends NodeVisitor
{
  private int[] count;
  private boolean endTagCheck;
  private int[] endTagCount;
  private NodeList[] endTags;
  private NodeList[] tags;
  private String[] tagsToBeFound;

  public TagFindingVisitor(String[] paramArrayOfString)
  {
    this(paramArrayOfString, false);
  }

  public TagFindingVisitor(String[] paramArrayOfString, boolean paramBoolean)
  {
    this.tagsToBeFound = paramArrayOfString;
    this.tags = new NodeList[paramArrayOfString.length];
    if (paramBoolean)
    {
      this.endTags = new NodeList[paramArrayOfString.length];
      this.endTagCount = new int[paramArrayOfString.length];
    }
    for (int i = 0; i < paramArrayOfString.length; ++i)
    {
      this.tags[i] = new NodeList();
      if (paramBoolean)
        this.endTags[i] = new NodeList();
    }
    this.count = new int[paramArrayOfString.length];
    this.endTagCheck = paramBoolean;
  }

  public int getEndTagCount(int paramInt)
  {
    return this.endTagCount[paramInt];
  }

  public int getTagCount(int paramInt)
  {
    return this.count[paramInt];
  }

  public Node[] getTags(int paramInt)
  {
    return this.tags[paramInt].toNodeArray();
  }

  public void visitEndTag(Tag paramTag)
  {
    if (!(this.endTagCheck))
      return;
    int i = 0;
    while (true)
    {
      if (i >= this.tagsToBeFound.length);
      if (paramTag.getTagName().equalsIgnoreCase(this.tagsToBeFound[i]))
      {
        int[] arrayOfInt = this.endTagCount;
        arrayOfInt[i] = (1 + arrayOfInt[i]);
        this.endTags[i].add(paramTag);
      }
      ++i;
    }
  }

  public void visitTag(Tag paramTag)
  {
    for (int i = 0; i < this.tagsToBeFound.length; ++i)
      if (paramTag.getTagName().equalsIgnoreCase(this.tagsToBeFound[i]))
      {
        int[] arrayOfInt = this.count;
        arrayOfInt[i] = (1 + arrayOfInt[i]);
        this.tags[i].add(paramTag);
      }
  }
}